package com.songcha.module_mine.ui.fragment.message.message_notify

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.songcha.library_base.interfaces.IApiResult
import com.songcha.library_base.mvvm.base.BaseViewModel
import com.songcha.library_business.proxy.userinfo.UserInfoManager
import com.songcha.library_common.helper.SharedPreferenceHelper
import com.songcha.library_common.util.TimeUtil
import com.songcha.library_network.bean.BaseBean
import com.songcha.module_mine.bean.SystemMessageDataBean

class MessageNotifyViewModel(app: Application):BaseViewModel<MessageNotifyRepository>(app) {
    var messageList=MutableLiveData<MutableList<SystemMessageDataBean.SystemMessageBean>>()

    fun updateSystemMessageReadTime(){
        handleApiDataObserver(repository!!.updateSystemMessageReadTime(),object :IApiResult<BaseBean>{
            override fun onSuccess(bean: BaseBean) {

            }
        })
    }

    fun getSystemMessage(){
        handleApiDataObserver(repository!!.getSystemMessage(),object :IApiResult<SystemMessageDataBean>{
            override fun onSuccess(bean: SystemMessageDataBean) {
                if(UserInfoManager.checkLogin()){
                    updateSystemMessageReadTime()
                }else{
                    SharedPreferenceHelper.setInt("stytem_msg","last_read_time",TimeUtil.getCurrentTimeSecond().toInt())
                }
                messageList.value=bean.data
            }
        },true)
    }
}